package com.xiaohua.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaohua.common.annotation.Log;
import com.xiaohua.common.core.controller.BaseController;
import com.xiaohua.common.core.domain.AjaxResult;
import com.xiaohua.common.enums.BusinessType;
import com.xiaohua.system.domain.XhOperations;
import com.xiaohua.system.service.IXhOperationsService;
import com.xiaohua.common.utils.poi.ExcelUtil;
import com.xiaohua.common.core.page.TableDataInfo;

/**
 * 操作记录Controller
 *
 * @author 小花
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/system/operations")
public class XhOperationsController extends BaseController {
    @Autowired
    private IXhOperationsService xhOperationsService;

    /**
     * 查询操作记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XhOperations xhOperations) {
        startPage();
        List<XhOperations> list = xhOperationsService.selectXhOperationsList(xhOperations);
        return getDataTable(list);
    }

    /**
     * 导出操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:operations:export')")
    @Log(title = "操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XhOperations xhOperations) {
        List<XhOperations> list = xhOperationsService.selectXhOperationsList(xhOperations);
        ExcelUtil<XhOperations> util = new ExcelUtil<XhOperations>(XhOperations.class);
        util.exportExcel(response, list, "操作记录数据");
    }

    /**
     * 获取操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:operations:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
        return success(xhOperationsService.selectXhOperationsByLogId(logId));
    }

    /**
     * 新增操作记录
     */
    @PreAuthorize("@ss.hasPermi('system:operations:add')")
    @Log(title = "操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XhOperations xhOperations) {
        return toAjax(xhOperationsService.insertXhOperations(xhOperations));
    }

    /**
     * 修改操作记录
     */
    @PreAuthorize("@ss.hasPermi('system:operations:edit')")
    @Log(title = "操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XhOperations xhOperations) {
        return toAjax(xhOperationsService.updateXhOperations(xhOperations));
    }

    /**
     * 删除操作记录
     */
    @PreAuthorize("@ss.hasPermi('system:operations:remove')")
    @Log(title = "操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(xhOperationsService.deleteXhOperationsByLogIds(logIds));
    }
}